﻿// ....................................................................................................................
//	Author: Copyright (C) 2012 Ing. Marek Hubal
//	Email: hubal@acasoftware.org
// ....................................................................................................................

using System;

namespace core
{
    /// <summary>Trieda IFileExplorerPanel</summary>
    public class IFileExplorerPanel : IBaseAppPanel
    {

        public delegate void SubPanelProcessRoutine(); // Delegate pre rutinu spracovania
        public delegate void SubPanelFinishProcessRoutine(); // Delegate pre rutinu ukoncenia spracovania
        public delegate void Delegate_FinishWorkMode(SubPanelFinishProcessRoutine pRoutine, string pResultMessage); // Delegate pre FinishWorkMode
        public delegate int Delegate_ShowEditor_ChooseFromList(string pCaption, string pNames, string pNotes, int pDefaultChoice, int pReserved);
        public delegate void Delegate_ReplaceProgressForm(IFileExplorer_BaseProgressForm pProgressForm);
        public delegate string Delegate_ShowEditor_EditString(string pCaption, string Value, bool pCanBeEmpty, int pMaxLength, string pAutoCompleteResourceName, string pAutoCompleteData, bool pPasswordMode, int pReserved);

        protected ISplitContainer FSplitPanel; // Rozdelovaci panel
        protected IFileExplorerSubPanel FLeftPanel, FRightPanel; // Objekt podpanelov
        protected ISimpleStatusStrip FMainStatus; // Hlavny status
        protected IFileExplorerSubPanel FActivePanel; // Aktivny panel
        protected long FMainStatusLastTimeUpdated; // Cas poslednej aktualizacie hlavneho statusu
        protected bool FLazyInit; // Priznak prvej aktualizacie obsahu po aktivacii
        protected string FLazyInitPath_Left, FLazyInitPath_Right; // Cesty pre oneskorenu inicializaciu
        protected string FLazyInitKeyValue_Left, FLazyInitKeyValue_Right; // Key. hodnoty pre oneskorenu inicializaciu
        protected int FLazyInitConnProvider_Left, FLazyInitConnProvider_Right; // Poskytovatelia spojenia
        protected bool FWorkMode; // Priznak modu spracovania
        protected IFileExplorer_BaseProgressForm FCurrentWorkProgressForm; // Aktualne okno pre zobrazenie progresu prace
        protected IFileExplorer_ProgressForm_ChooseFromList FCurrentChoiceForm; // Aktualne okno pre ziskanie volby
        protected IFileExplorer_ProgressForm_EditString FCurrentEditStringForm; // Aktualne okno pre ziskanie volby
        protected int FCurrentChoiceFormResultValue; // Vysledok posledneho vyberu
        protected string FCurrentEditStringFormResultValue; // Vysledok posledneho editacie retazca

        /// <summary>Property: TabName</summary>
        public override string TabName
        {
            get
            {
                if (FCustomTabName != "") return FCustomTabName; // Je nastaveny vlastny nazov zalozky?
                return IsDualPanelMode ? lang.FILE_EXPLORER_TEXT_1 : lang.FILE_EXPLORER_TEXT_1_1;
            }
        }
        /// <summary>Property: IsDualPanelMode</summary>
        public bool IsDualPanelMode
        {
            get
            {
                return FSplitPanel.PanelsVisibility == 3;
            }
        }
        /// <summary>Property: ActivePanel</summary>
        public IFileExplorerSubPanel ActivePanel
        {
            get
            {
                return FActivePanel == null ? FLeftPanel : FActivePanel;
            }
        }
        /// <summary>Property: InActivePanel</summary>
        public IFileExplorerSubPanel InActivePanel
        {
            get
            {
                return (FActivePanel == null) || (FActivePanel == FLeftPanel) ? FRightPanel : FLeftPanel;
            }
        }
        /// <summary>Ziskanie pozicie panela</summary>
        /// <param name="pPanel">objekt panela</param>
        /// <returns>pozicia</returns>
        public int GetPanelPosition(IFileExplorerSubPanel pPanel)
        {
            return pPanel == FLeftPanel ? ICmd.CMD_PANEL_TARGET_LEFT : ICmd.CMD_PANEL_TARGET_RIGHT;
        }
        /// <summary>Ziskanie opacneho panela</summary>
        /// <param name="pPanel">panel, ktory to ziada</param>
        /// <returns>opacny panel</returns>
        public IFileExplorerSubPanel GetOppositePanel(IFileExplorerSubPanel pPanel)
        {
            return pPanel == FLeftPanel ? FRightPanel : FLeftPanel;
        }
        /// <summary>Test ci je zadany panel zobrazeny</summary>
        /// <param name="pPanel">objekt panela</param>
        /// <returns>true / false</returns>
        public bool IsPanelVisible(IFileExplorerSubPanel pPanel)
        {
            if (pPanel == FLeftPanel) return FSplitPanel.LeftPanelVisible;
            return FSplitPanel.RightPanelVisible;
        }
        /// <summary>Property: InitString</summary>
        public override string InitString
        {
            get
            {
                using (IParamList L = new IParamList()) // Vytvorim inicializacne parametre
                {
                    L.SetParam("LAZY_INIT", true); // Okamzite nacitanie
                    L.SetParam("LEFT_PATH", FLazyInit ? FLazyInitPath_Left : FLeftPanel.InitPath); // Lava cesta
                    L.SetParam("LEFT_KEY_VALUE", FLazyInit ? FLazyInitKeyValue_Left : FLeftPanel.InitKeyValue); // Ulozim key hodnotu
                    L.SetParam("RIGHT_PATH", FLazyInit ? FLazyInitPath_Right : FRightPanel.InitPath); // Prava cesta
                    L.SetParam("RIGHT_KEY_VALUE", FLazyInit ? FLazyInitKeyValue_Right : FRightPanel.InitKeyValue); // Ulozim key hodnotu
                    L.SetParam("ACT_PANEL", ActivePanel == FLeftPanel ? 0 : 1); // Ulozim aktivny panel
                    SaveSettings(); // Ulozim cele nastavenie

                    return L.Serialize(false);
                }
            }
        }
        /// <summary>Property: CanClose</summary>
        public override bool CanClose
        {
            get
            {
                return !FWorkMode;
            }
        }

        /// <summary>Event: Opening pre menu 'View'</summary>
        /// <param name="pSender">zdroj</param>
        /// <param name="e">parameter</param>
        protected void Event_MenuOpening_Show(object pSender, EventArgs e)
        {
            IToolStripDropDownButton B = (IToolStripDropDownButton)pSender; // Menu
            B.DropDownItems.Clear(); // Zrusim aktualny obsah

            IToolStripMenuItem M;
            M = IToolStrip.CreateCMDMenuItem(B.DropDownItems, lang.MENU_ITEM_TEXT_FILE_EXPLORER_PANEL_MENU_SHOW_LEFT_PANEL_VISIBILITY, ICmd.CMD_ID_FILE_EXPLORER_SHOW_LEFT_PANEL, ICmd.CMD_APP_TARGET_ACTIVE, ICmd.CMD_PANEL_TARGET_NONE); M.Checked = FSplitPanel.LeftPanelVisible;
            M = IToolStrip.CreateCMDMenuItem(B.DropDownItems, lang.MENU_ITEM_TEXT_FILE_EXPLORER_PANEL_MENU_SHOW_RIGHT_PANEL_VISIBILITY, ICmd.CMD_ID_FILE_EXPLORER_SHOW_RIGHT_PANEL, ICmd.CMD_APP_TARGET_ACTIVE, ICmd.CMD_PANEL_TARGET_NONE); M.Checked = FSplitPanel.RightPanelVisible;
            IToolStrip.CreateSeparator(B.DropDownItems);
            M = IToolStrip.CreateCMDMenuItem(B.DropDownItems, lang.MENU_ITEM_TEXT_FILE_EXPLORER_PANEL_MENU_SHOW_CENTER_PANELS, ICmd.CMD_ID_FILE_EXPLORER_CENTER_PANELS, ICmd.CMD_APP_TARGET_ACTIVE, ICmd.CMD_PANEL_TARGET_NONE);
            IToolStrip.CreateSeparator(B.DropDownItems);
            M = IToolStrip.CreateCMDMenuItem(B.DropDownItems, lang.MENU_ITEM_TEXT_FILE_EXPLORER_PANEL_MENU_SHOW_SWAP_ORIENTATION, ICmd.CMD_ID_FILE_EXPLORER_SWAP_ORIENTATION, ICmd.CMD_APP_TARGET_ACTIVE, ICmd.CMD_PANEL_TARGET_NONE); M.Checked = FSplitPanel.VerticalPanels;
            IToolStrip.CreateSeparator(B.DropDownItems);
            IToolStrip.CreateCMDMenuItem(B.DropDownItems, lang.MENU_ITEM_TEXT_FILE_EXPLORER_SHOW_SWAP_PANELS, ICmd.CMD_ID_FILE_EXPLORER_EXCHANGE_PANELS, ICmd.CMD_APP_TARGET_ACTIVE, ICmd.CMD_PANEL_TARGET_NONE);
        }
        /// <summary>Event: SplitterChanging</summary>
        /// <param name="pSender">zdroj</param>
        /// <param name="pPosition">parameter</param>
        protected void Event_SplitterChanging(object pSender, double pPosition)
        {
            UpdateMainStatus(string.Format(lang.FILE_EXPLORER_TEXT_2, pPosition));
        }
        /// <summary>Event: SplitterChanged</summary>
        /// <param name="pSender">zdroj</param>
        /// <param name="pPosition">parameter</param>
        protected void Event_SplitterChanged(object pSender, double pPosition)
        {
            UpdateMainStatus("");
        }
        /// <summary>Event: Opening pre menu 'Left panel'</summary>
        /// <param name="pSender">zdroj</param>
        /// <param name="e">parameter</param>
        protected void Event_MenuOpening_LeftPanel(object pSender, EventArgs e)
        {
            IToolStripDropDownButton B = (IToolStripDropDownButton)pSender;
            B.DropDownItems.Clear(); // Zrusim aktualny obsah
            FLeftPanel.CreatePanelMenu(B.DropDownItems); // Volam vytvorenie menu
        }
        /// <summary>Event: Opening pre menu 'Right panel'</summary>
        /// <param name="pSender">zdroj</param>
        /// <param name="e">parameter</param>
        protected void Event_MenuOpening_RightPanel(object pSender, EventArgs e)
        {
            IToolStripDropDownButton B = (IToolStripDropDownButton)pSender;
            B.DropDownItems.Clear(); // Zrusim aktualny obsah
            FRightPanel.CreatePanelMenu(B.DropDownItems); // Volam vytvorenie menu
        }
        
        /// <summary>Metoda: OnResize</summary>
        /// <param name="e">parameter</param>
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e); // Volam predchodcu
            if (FWorkMode) FCurrentWorkProgressForm.CenterPanel();
        }

        /// <summary>Konstruktor</summary>
        public IFileExplorerPanel()
        {
            ID = IBaseAppPanel.APP_PANEL_ID_FILE_EXPLORER;
            FCMDGroupID = ICmd.CMD_GROUP_FILE_EXPLORER;
            FActivePanel = null;
            FMainStatusLastTimeUpdated = 0;
            FWorkMode = false;
        }

        /// <summary>Metoda: Init</summary>
        /// <param name="pInitStr">parameter</param>
        /// <returns>true / false</returns>
        public override bool Init(string pInitStr = "")
        {
            if (!base.Init(pInitStr)) return false; // Volam predchodcu

            using (IParamList L = new IParamList())
            {
                L.Deserialize(pInitStr, false); // Deserializacia vstupneho inic. retazca

                int SouceSettings = L.GetParam("SOURCE_SETTINGS", -1); // Kopirovat nastavenie?
                if (SouceSettings != -1)
                {
                    CloneSettings(SouceSettings, TabPosition);
                    LoadSettings();
                }

                // Split container...
                FSplitPanel = new ISplitContainer(); FSplitPanel.Dock = System.Windows.Forms.DockStyle.Fill; FSplitPanel.TabStop = false;

                // Vytvorim lavy / horny panel
                FLeftPanel = new IFileExplorerSubPanel(); FLeftPanel.Dock = System.Windows.Forms.DockStyle.Fill; FLeftPanel.SerializedParams = FParams.GetParam("LP", ""); FLeftPanel.ParentPanel = this; FLeftPanel.Create();
                FSplitPanel.Panel1.Controls.Add(FLeftPanel);
                // Vytvorim pravy / dolny panel
                FRightPanel = new IFileExplorerSubPanel(); FRightPanel.Dock = System.Windows.Forms.DockStyle.Fill; FRightPanel.SerializedParams = FParams.GetParam("RP", ""); FRightPanel.ParentPanel = this; FRightPanel.Create();
                FSplitPanel.Panel2.Controls.Add(FRightPanel);

                FSplitPanel.VerticalPanels = FParams.GetParam("VP", true); // Nastavim ulozene hodnoty
                FSplitPanel.SplitterPosition = Math.Round(FParams.GetParam("SP", 50.0), 1);
                FSplitPanel.PanelsVisibility = FParams.GetParam("PV", 3);

                // Hlavny status
                FMainStatus = new ISimpleStatusStrip(); FMainStatus.Dock = System.Windows.Forms.DockStyle.Bottom;

                Controls.AddRange(new System.Windows.Forms.Control[] { FSplitPanel, FMainStatus }); // Zaradim do controls

                FSplitPanel.SplitterChanging += Event_SplitterChanging; FSplitPanel.SplitterChanged += Event_SplitterChanged;

                FLazyInit = L.GetParam("LAZY_INIT", true);
                FLazyInitPath_Left = FLazyInit ? L.GetParam("LEFT_PATH", "") : ""; // Urcim cesty
                FLazyInitPath_Right = FLazyInit ? L.GetParam("RIGHT_PATH", "") : "";
                FLazyInitKeyValue_Left = L.GetParam("LEFT_KEY_VALUE", "");
                FLazyInitKeyValue_Right = L.GetParam("RIGHT_KEY_VALUE", "");
                FLazyInitConnProvider_Left = L.GetParam("LEFT_CONN_PROV", 0);
                FLazyInitConnProvider_Right = L.GetParam("RIGHT_CONN_PROV", 0);

                if (FLazyInit) // Oneskorena inicializacia?
                {
                    FLeftPanel.Go("", true, true, "", true, false); FRightPanel.Go("", true, true, "", true, false); // Nacitam root
                }
                else
                {
                    // Nacitam priame cesty
                    FLeftPanel.Go(L.GetParam("LEFT_PATH", ""), true, true, L.GetParam("LEFT_KEY_VALUE", ""), true, true, L.GetParam("LEFT_CONN_PROV", 0)); FRightPanel.Go(L.GetParam("RIGHT_PATH", ""), true, true, L.GetParam("RIGHT_KEY_VALUE", ""), true, true, L.GetParam("RIGHT_CONN_PROV", 0));
                }

                FActivePanel = L.GetParam("ACT_PANEL", 0) == 0 ? FLeftPanel : FRightPanel; // Nastavim aktualny subpanel
            }

            return true; // Vsetko OK
        }
        /// <summary>Metoda: Close</summary>
        public override void Close()
        {
            base.Close(); // Volam predchodcu
        }
        /// <summary>Metoda: CreatePanelMenu</summary>
        /// <param name="pParent">parameter</param>
        public override void CreatePanelMenu(System.Windows.Forms.ToolStripItemCollection pParent)
        {
            if (FWorkMode) return; // Je pracovny mod?

            IToolStripDropDownButton B; IToolStripMenuItem M;

            B = IToolStrip.CreateDropDownButton(pParent, lang.MENU_ITEM_TEXT_FILE_EXPLORER_PANEL_MENU_LEFT, null, Event_MenuOpening_LeftPanel); B.Enabled = FSplitPanel.LeftPanelVisible;
            IToolStrip.CreateSeparator(pParent);
            B = IToolStrip.CreateDropDownButton(pParent, lang.MENU_ITEM_TEXT_FILE_EXPLORER_PANEL_MENU_RIGHT, null, Event_MenuOpening_RightPanel); B.Enabled = FSplitPanel.RightPanelVisible;
            IToolStrip.CreateSeparator(pParent);

            B = IToolStrip.CreateDropDownButton(pParent, lang.MENU_ITEM_TEXT_FILE_EXPLORER_NAVIGATION); // Vytvorim podmenu
            B.CreateCMDMenuItem(lang.MENU_ITEM_TEXT_FILE_EXPLORER_NAVIGATION_OPEN, ICmd.CMD_ID_FILE_EXPLORER_EXPAND, ICmd.CMD_APP_TARGET_ACTIVE, ICmd.CMD_PANEL_TARGET_ACTIVE);
            B.CreateCMDMenuItem(lang.MENU_ITEM_TEXT_FILE_EXPLORER_NAVIGATION_GO_BACK, ICmd.CMD_ID_FILE_EXPLORER_GO_BACK, ICmd.CMD_APP_TARGET_ACTIVE, ICmd.CMD_PANEL_TARGET_ACTIVE);
            B.CreateSeparator();
            B.CreateCMDMenuItem(lang.MENU_ITEM_TEXT_FILE_EXPLORER_NAVIGATION_DEVICES, ICmd.CMD_ID_FILE_EXPLORER_GO_DEVICES, ICmd.CMD_APP_TARGET_ACTIVE, ICmd.CMD_PANEL_TARGET_ACTIVE);
            B.CreateCMDMenuItem(lang.MENU_ITEM_TEXT_FILE_EXPLORER_NAVIGATION_DEVICE_ROOT, ICmd.CMD_ID_FILE_EXPLORER_GO_DEVICE_ROOT, ICmd.CMD_APP_TARGET_ACTIVE, ICmd.CMD_PANEL_TARGET_ACTIVE);
            B.CreateSeparator();
            M = B.CreateMenuItem(lang.MENU_ITEM_TEXT_FILE_EXPLORER_NAVIGATION_SPECIAL);
            M.CreateCMDMenuItem(lang.MENU_ITEM_TEXT_FILE_EXPLORER_NAVIGATION_SPECIAL_DESKTOP, ICmd.CMD_ID_FILE_EXPLORER_GO_SPECIAL_DESKTOP, ICmd.CMD_APP_TARGET_ACTIVE, ICmd.CMD_PANEL_TARGET_ACTIVE);
            M.CreateSeparator();
            M.CreateCMDMenuItem(lang.MENU_ITEM_TEXT_FILE_EXPLORER_NAVIGATION_SPECIAL_MY_DOCS, ICmd.CMD_ID_FILE_EXPLORER_GO_SPECIAL_MY_DOCS, ICmd.CMD_APP_TARGET_ACTIVE, ICmd.CMD_PANEL_TARGET_ACTIVE);
            M.CreateCMDMenuItem(lang.MENU_ITEM_TEXT_FILE_EXPLORER_NAVIGATION_SPECIAL_MY_IMAGES, ICmd.CMD_ID_FILE_EXPLORER_GO_SPECIAL_MY_IMAGES, ICmd.CMD_APP_TARGET_ACTIVE, ICmd.CMD_PANEL_TARGET_ACTIVE);
            M.CreateCMDMenuItem(lang.MENU_ITEM_TEXT_FILE_EXPLORER_NAVIGATION_SPECIAL_MY_MUSIC, ICmd.CMD_ID_FILE_EXPLORER_GO_SPECIAL_MY_MUSIC, ICmd.CMD_APP_TARGET_ACTIVE, ICmd.CMD_PANEL_TARGET_ACTIVE);
            M.CreateCMDMenuItem(lang.MENU_ITEM_TEXT_FILE_EXPLORER_NAVIGATION_SPECIAL_MY_VIDEOS, ICmd.CMD_ID_FILE_EXPLORER_GO_SPECIAL_MY_VIDEOS, ICmd.CMD_APP_TARGET_ACTIVE, ICmd.CMD_PANEL_TARGET_ACTIVE);
            M.CreateSeparator();
            M.CreateCMDMenuItem(lang.MENU_ITEM_TEXT_FILE_EXPLORER_NAVIGATION_SPECIAL_WINDOWS, ICmd.CMD_ID_FILE_EXPLORER_GO_SPECIAL_WINDOWS, ICmd.CMD_APP_TARGET_ACTIVE, ICmd.CMD_PANEL_TARGET_ACTIVE);
            M.CreateCMDMenuItem(lang.MENU_ITEM_TEXT_FILE_EXPLORER_NAVIGATION_SPECIAL_SYSTEM, ICmd.CMD_ID_FILE_EXPLORER_GO_SPECIAL_SYSTEM, ICmd.CMD_APP_TARGET_ACTIVE, ICmd.CMD_PANEL_TARGET_ACTIVE);
            M.CreateCMDMenuItem(lang.MENU_ITEM_TEXT_FILE_EXPLORER_NAVIGATION_SPECIAL_START, ICmd.CMD_ID_FILE_EXPLORER_GO_SPECIAL_START, ICmd.CMD_APP_TARGET_ACTIVE, ICmd.CMD_PANEL_TARGET_ACTIVE);
            M.CreateSeparator();
            M.CreateCMDMenuItem(lang.MENU_ITEM_TEXT_FILE_EXPLORER_NAVIGATION_SPECIAL_TEMP, ICmd.CMD_ID_FILE_EXPLORER_GO_SPECIAL_TEMP, ICmd.CMD_APP_TARGET_ACTIVE, ICmd.CMD_PANEL_TARGET_ACTIVE);
            B.CreateSeparator();
            B.CreateCMDMenuItem(lang.MENU_ITEM_TEXT_FILE_EXPLORER_NAVIGATION_PREV_DEVICE, ICmd.CMD_ID_FILE_EXPLORER_GO_PREV_DEVICE, ICmd.CMD_APP_TARGET_ACTIVE, ICmd.CMD_PANEL_TARGET_ACTIVE);
            B.CreateCMDMenuItem(lang.MENU_ITEM_TEXT_FILE_EXPLORER_NAVIGATION_NEXT_DEVICE, ICmd.CMD_ID_FILE_EXPLORER_GO_NEXT_DEVICE, ICmd.CMD_APP_TARGET_ACTIVE, ICmd.CMD_PANEL_TARGET_ACTIVE);
            B.CreateSeparator();
            B.CreateCMDMenuItem(lang.MENU_ITEM_TEXT_FILE_EXPLORER_NAVIGATION_CHOOSE, ICmd.CMD_ID_FILE_EXPLORER_GO_CHOOSE, ICmd.CMD_APP_TARGET_ACTIVE, ICmd.CMD_PANEL_TARGET_ACTIVE);
            B.CreateCMDMenuItem(lang.MENU_ITEM_TEXT_FILE_EXPLORER_NAVIGATION_DIRECT_CHOOSE, ICmd.CMD_ID_FILE_EXPLORER_GO_DIRECT, ICmd.CMD_APP_TARGET_ACTIVE, ICmd.CMD_PANEL_TARGET_ACTIVE);
            B.CreateSeparator();
            B.CreateCMDMenuItem(lang.MENU_ITEM_TEXT_FILE_EXPLORER_NAVIGATION_SAME_PANELS, ICmd.CMD_ID_FILE_EXPLORER_GO_SAME_PANELS, ICmd.CMD_APP_TARGET_ACTIVE, ICmd.CMD_PANEL_TARGET_ACTIVE);

            IToolStrip.CreateSeparator(pParent);
            IToolStrip.CreateDropDownButton(pParent, lang.MENU_ITEM_TEXT_FILE_EXPLORER_PANEL_MENU_SHOW, null, Event_MenuOpening_Show);

            IToolStrip.CreateSeparator(pParent);
            B = IToolStrip.CreateDropDownButton(pParent, lang.MENU_ITEM_TEXT_FILE_EXPLORER_TOOLS);
            B.CreateCMDMenuItem(lang.MENU_ITEM_TEXT_FILE_EXPLORER_EXPORT_CD_TRACKS, ICmd.CMD_ID_FILE_EXPLORER_EXTRACT_CD_TRACKS, ICmd.CMD_APP_TARGET_ACTIVE, ICmd.CMD_PANEL_TARGET_ACTIVE);
        }
        /// <summary>Nacitanie nastavenia</summary>
        public override void LoadSettings()
        {
            base.LoadSettings(); // Volam predchodcu
        }
        /// <summary>Ulozenie nastavenia</summary>
        public override void SaveSettings()
        {
            FParams.SetParam("VP", FSplitPanel.VerticalPanels); // Ulozim
            FParams.SetParam("SP", FSplitPanel.SplitterPosition);
            FParams.SetParam("PV", FSplitPanel.PanelsVisibility);
            FParams.SetParam("LP", FLeftPanel.SerializedParams);
            FParams.SetParam("RP", FRightPanel.SerializedParams);
            base.SaveSettings(); // Volam predchodcu
        }
        /// <summary>Aktualizacia obsahu hlavneho status</summary>
        /// <param name="pMessage">sprava</param>
        /// <param name="pForceUpdate">priznak okamzitej aktualizacie</param>
        public void UpdateMainStatus(string pMessage, bool pForceUpdate = false)
        {
            FMainStatus.SimpleText = pMessage;
            if (pForceUpdate)
            {
                long L = DateTime.Now.Ticks;
                if (L - FMainStatusLastTimeUpdated > 500 * 10 * 1000) // Zabranim prilis castej aktualizacii
                {
                    IApp.DoEvents(FMainStatus.Handle);
                    FMainStatusLastTimeUpdated = L;
                }
            }
        }
        /// <summary>Vykonanie prikazu</summary>
        /// <param name="pCMD_ID">ID prikazu</param>
        /// <param name="pAPP_TARGET">aplikacia</param>
        /// <param name="pPANEL_TARGET">panel</param>
        /// <returns>true / false</returns>
        public override bool ExecCMD(int pCMD_ID, int pAPP_TARGET, int pPANEL_TARGET)
        {
            if (FWorkMode) return false; // Ziadne prikazy ak sa nieco spracovava

            if (base.ExecCMD(pCMD_ID, pAPP_TARGET, pPANEL_TARGET)) return true; // Volam predchodcu

            switch (pCMD_ID)
            {
                case ICmd.CMD_ID_FILE_EXPLORER_EXTRACT_CD_TRACKS:
                    {
                        if (IFileExplorerForm_ExportCDTracks.FormInstance == null)
                        {
                            IFileExplorerForm_ExportCDTracks F = new IFileExplorerForm_ExportCDTracks(); // Vytvorim okno
                            F.Show(); // Zobrazim
                        }
                        else
                        {
                            IFileExplorerForm_ExportCDTracks.FormInstance.Activate();
                            IFileExplorerForm_ExportCDTracks.FormInstance.BringToFront();
                        }
                        return true; // Prikaz bol vykonany
                    }
                case ICmd.CMD_ID_FILE_EXPLORER_MAP_NETWORK_DRIVE:
                    {
                        IWin32.Mpr.WNetConnectionDialog(IApp.AppForm.Handle, 1);
                        return true; // Prikaz bol vykonany
                    }
                case ICmd.CMD_ID_FILE_EXPLORER_UNMAP_NETWORK_DRIVE:
                    {
                        IWin32.Mpr.WNetDisconnectDialog(IApp.AppForm.Handle, 1);
                        return true; // Prikaz bol vykonany
                    }
                case ICmd.CMD_ID_FILE_EXPLORER_NEW_TAB_CURRENT_PATH:
                    {
                        using (IParamList L = new IParamList()) // Vytvorim inicializacne parametre
                        {
                            L.SetParam("LAZY_INIT", true); // Okamzite nacitanie
                            if (ActivePanel == FLeftPanel) {
                                L.SetParam("LEFT_PATH", FLeftPanel.CurrentPath); // Lava cesta
                                L.SetParam("LEFT_KEY_VALUE", FLeftPanel.ActiveKeyValue); // Ulozim key hodnotu
                                L.SetParam("LEFT_CONN_PROV", FLeftPanel.ActiveConnectionProvider);
                            }
                            if (ActivePanel == FRightPanel) {
                                L.SetParam("RIGHT_PATH", FRightPanel.CurrentPath); // Prava cesta
                                L.SetParam("RIGHT_KEY_VALUE", FRightPanel.ActiveKeyValue); // Ulozim key hodnotu
                                L.SetParam("RIGHT_CONN_PROV", FRightPanel.ActiveConnectionProvider);
                            }
                            L.SetParam("SOURCE_SETTINGS", TabPosition); // Skopirovat nastavenie
                            L.SetParam("ACT_PANEL", ActivePanel == FLeftPanel ? 0 : 1); // Ulozim aktivny panel
                            SaveSettings(); // Ulozim cele nastavenie

                            IBaseAppPanel P = IApp.AppForm.AddNewPanel(IBaseAppPanel.APP_PANEL_ID_FILE_EXPLORER, L.Serialize(false)); // Vytvorim panel
                            IApp.AppForm.SetActivePanel(P); // Aktivujem panel
                        }
                        return true; // Vsetko OK
                    }
                case ICmd.CMD_ID_FILE_EXPLORER_NEW_TAB_CURRENT_ITEM:
                    {
                        if (!FActivePanel.CanExpandActiveItem) return true; // Neda sa expandovat?

                        using (IParamList L = new IParamList()) // Vytvorim inicializacne parametre
                        {
                            L.SetParam("LAZY_INIT", true); // Okamzite nacitanie
                            if (ActivePanel == FLeftPanel)
                            {
                                L.SetParam("LEFT_PATH", FLeftPanel.ActiveItemExpandPath); // Lava cesta
                                L.SetParam("LEFT_CONN_PROV", FLeftPanel.ActiveItemConnectionProvider);
                            }
                            if (ActivePanel == FRightPanel)
                            {
                                L.SetParam("RIGHT_PATH", FRightPanel.ActiveItemExpandPath); // Prava cesta
                                L.SetParam("RIGHT_CONN_PROV", FRightPanel.ActiveItemConnectionProvider);
                            }
                            L.SetParam("SOURCE_SETTINGS", TabPosition); // Skopirovat nastavenie
                            L.SetParam("ACT_PANEL", ActivePanel == FLeftPanel ? 0 : 1); // Ulozim aktivny panel
                            SaveSettings(); // Ulozim cele nastavenie

                            IBaseAppPanel P = IApp.AppForm.AddNewPanel(IBaseAppPanel.APP_PANEL_ID_FILE_EXPLORER, L.Serialize(false)); // Vytvorim panel
                            IApp.AppForm.SetActivePanel(P); // Aktivujem panel
                        }
                        return true; // Vsetko OK
                    }
                case ICmd.CMD_ID_FILE_EXPLORER_EXCHANGE_PANELS:
                    {
                        if (!IsDualPanelMode) return true; // Nie su oba panely?

                        FSplitPanel.SuspendLayout(); // Zakazem layout
                        FSplitPanel.Panel1.Controls.Remove(FLeftPanel); FSplitPanel.Panel2.Controls.Remove(FRightPanel); // Odoberiem z controls
                        IFileExplorerSubPanel P = FLeftPanel; FLeftPanel = FRightPanel; FRightPanel = P; // Vymenim objekty
                        FParams.SetParam("LP", FLeftPanel.SerializedParams); // Ulozim nove nastavenia
                        FParams.SetParam("RP", FRightPanel.SerializedParams);
                        FSplitPanel.Panel1.Controls.Add(FLeftPanel); FSplitPanel.Panel2.Controls.Add(FRightPanel); // Vratim panely do controls
                        FSplitPanel.ResumeLayout(true); // Povolim layout

                        return true; // Vsetko OK
                    }
                case ICmd.CMD_ID_FILE_EXPLORER_CENTER_PANELS:
                    {
                        if (IsDualPanelMode) FSplitPanel.SplitterPosition = 50.0;
                        return true; // Vsetko OK
                    }
                case ICmd.CMD_ID_FILE_EXPLORER_SWAP_ORIENTATION:
                    {
                        if (IsDualPanelMode) FSplitPanel.VerticalPanels = !FSplitPanel.VerticalPanels;
                        return true; // Vsetko OK
                    }
                case ICmd.CMD_ID_FILE_EXPLORER_SHOW_LEFT_PANEL:
                    {
                        FSplitPanel.LeftPanelVisible = !FSplitPanel.LeftPanelVisible;
                        UpdateTabPageName(); // Volam aktualizaciu nazvu
                        IApp.AppForm.UpdateMainMenu(); // Aktualizujem menu
                        if (!FSplitPanel.LeftPanelVisible) ChangeActivePanel(FRightPanel);
                        return true; // Vsetko OK
                    }
                case ICmd.CMD_ID_FILE_EXPLORER_SHOW_RIGHT_PANEL:
                    {
                        FSplitPanel.RightPanelVisible = !FSplitPanel.RightPanelVisible;
                        UpdateTabPageName(); // Volam aktualizaciu nazvu
                        IApp.AppForm.UpdateMainMenu();
                        if (!FSplitPanel.RightPanelVisible) ChangeActivePanel(FLeftPanel);
                        return true; // Vsetko OK
                    }
            }

            switch (pPANEL_TARGET)
            {
                case ICmd.CMD_PANEL_TARGET_LEFT: return FLeftPanel.ExecCMD(pCMD_ID, pAPP_TARGET, pPANEL_TARGET);
                case ICmd.CMD_PANEL_TARGET_RIGHT: return FRightPanel.ExecCMD(pCMD_ID, pAPP_TARGET, pPANEL_TARGET);
                case ICmd.CMD_PANEL_TARGET_INACTIVE: return InActivePanel.ExecCMD(pCMD_ID, pAPP_TARGET, pPANEL_TARGET);
                case ICmd.CMD_PANEL_TARGET_ACTIVE: return ActivePanel.ExecCMD(pCMD_ID, pAPP_TARGET, pPANEL_TARGET);
                case ICmd.CMD_PANEL_TARGET_BOTH:
                    {
                        bool B = FLeftPanel.ExecCMD(pCMD_ID, pAPP_TARGET, pPANEL_TARGET);
                        B |= FRightPanel.ExecCMD(pCMD_ID, pAPP_TARGET, pPANEL_TARGET);
                        return B;
                    }
                default: return false; // Prikaz nebol vykonany
            }
        }
        /// <summary>Aktualizacia objektu po zmene nastavenia</summary>
        public override void UpdateAfterChangeSettings()
        {
            FLeftPanel.UpdateAfterChangeSettings(); // Volam aktualizaciu podpanelov
            FRightPanel.UpdateAfterChangeSettings();
        }
        /// <summary>Zmena aktivneho panela</summary>
        /// <param name="pPanel">panel</param>
        public void ChangeActivePanel(IFileExplorerSubPanel pPanel)
        {
            if (!IApp.AppForm.CanPanelActivate) return; // Je zakaz aktivacie?

            if (FActivePanel == pPanel) return;
            FActivePanel = pPanel;
            InActivePanel.DeactivatePanel(); ActivePanel.ActivatePanel(); // Aktivujem a deaktivujem panely
        }
        /// <summary>Aktualizacia objektu po zmene vizualnej temy</summary>
        public override void UpdateAfterChangeVisualTheme()
        {
            FLeftPanel.UpdateAfterChangeVisualTheme();
            FRightPanel.UpdateAfterChangeVisualTheme();
        }
        /// <summary>Aktivacia panela</summary>
        public override void ActivatePanel()
        {
            if (FWorkMode) // Je spracovavanie?
            {
                if (FCurrentWorkProgressForm != null) FCurrentWorkProgressForm.ActivatePanel();
                else FCurrentWorkProgressForm.ActivatePanel();
                return;
            }

            if (FLazyInit)
            {
                FLazyInit = false;
                if (FLazyInitPath_Left != "") FLeftPanel.Go(FLazyInitPath_Left, false, false, FLazyInitKeyValue_Left, true, true, FLazyInitConnProvider_Left);
                if (FLazyInitPath_Right != "") FRightPanel.Go(FLazyInitPath_Right, false, false, FLazyInitKeyValue_Right, true, true, FLazyInitConnProvider_Right);
            }

            FLeftPanel.ActiveItemIndex = FLeftPanel.ActiveItemIndex;
            FRightPanel.ActiveItemIndex = FRightPanel.ActiveItemIndex;

            ActivePanel.ActivatePanel();
        }
        /// <summary>Duplikovanie panela</summary>
        public override void DuplicatePanel()
        {
            using (IParamList L = new IParamList()) // Vytvorim inicializacne parametre
            {
                L.SetParam("LAZY_INIT", true); // Okamzite nacitanie
                L.SetParam("LEFT_PATH", FLeftPanel.CurrentPath); // Lava cesta
                L.SetParam("LEFT_KEY_VALUE", FLeftPanel.ActiveKeyValue); // Ulozim key hodnotu
                L.SetParam("RIGHT_PATH", FRightPanel.CurrentPath); // Prava cesta
                L.SetParam("RIGHT_KEY_VALUE", FRightPanel.ActiveKeyValue); // Ulozim key hodnotu
                L.SetParam("SOURCE_SETTINGS", TabPosition); // Skopirovat nastavenie
                L.SetParam("ACT_PANEL", ActivePanel == FLeftPanel ? 0 : 1); // Ulozim aktivny panel
                L.SetParam("LEFT_CONN_PROV", FLeftPanel.ActiveConnectionProvider);
                L.SetParam("RIGHT_CONN_PROV", FRightPanel.ActiveConnectionProvider);
                SaveSettings(); // Ulozim cele nastavenie

                IBaseAppPanel P = IApp.AppForm.AddNewPanel(IBaseAppPanel.APP_PANEL_ID_FILE_EXPLORER, L.Serialize(false)); // Vytvorim panel
                IApp.AppForm.SetActivePanel(P); // Aktivujem panel
            }
        }

        /// <summary>Spustenie modu spracovania</summary>
        /// <param name="pProgressForm">progress formular</param>
        public void StartWorkMode(IFileExplorer_BaseProgressForm pProgressForm, SubPanelProcessRoutine pRoutine)
        {
            IApp.AppForm.CanPanelActivate = false;
            FWorkMode = true; // Nastavim mod spracovania
            FCurrentWorkProgressForm = pProgressForm; // Ulozim progress okno

            FLeftPanel.Enabled = false; FRightPanel.Enabled = false; FSplitPanel.Enabled = false; // Zakazem panely
            pProgressForm.SetParent(this); pProgressForm.BringToFront(); // Zobrazim progress okno

            IApp.AppForm.UpdateMainMenu(); // Aktualizujem menu
            ActivatePanel();
            IApp.AppForm.SetTabIcon(this, 0); // Nastavim ikonu spracovania

            System.Threading.Thread Thr = new System.Threading.Thread(new System.Threading.ThreadStart(pRoutine)); // Vytvorim proces
            Thr.IsBackground = true;
            Thr.SetApartmentState(System.Threading.ApartmentState.STA);
            Thr.Priority = System.Threading.ThreadPriority.Lowest;
            Thr.Start(); // Spustim proces
        }
        /// <summary>Ukoncenie modu spracovania</summary>
        /// <param name="pRoutine">ukoncovacia rutina</param>
        /// <param name="pResultMessage">sprava o vysledku pre zobrazenie do okna</param>
        public void FinishWorkMode(SubPanelFinishProcessRoutine pRoutine, string pResultMessage = null)
        {
            if (InvokeRequired) // Treba invoke?
            {
                Invoke(new Delegate_FinishWorkMode(FinishWorkMode), new object[] {pRoutine, pResultMessage});
                return;
            }

            if (FCurrentWorkProgressForm != null)
            {
                Controls.Remove(FCurrentWorkProgressForm);
                FCurrentWorkProgressForm.Dispose();
                FCurrentWorkProgressForm = null;
            }

            IApp.App.EnabledEscMonitor = false;
            if (string.IsNullOrEmpty(pResultMessage))
            {

                FWorkMode = false; // Zrusim mod spracovania
                FLeftPanel.Enabled = true; FRightPanel.Enabled = true; FSplitPanel.Enabled = true; // Povolim panely

                IApp.AppForm.UpdateMainMenu(); // Aktualizujem menu
                ActivatePanel(); // Aktivujem panel
                IApp.AppForm.CanPanelActivate = true;
                IApp.AppForm.SetTabIcon(this, -1); // Zrusim ikonu spracovania

                if (pRoutine != null) pRoutine(); // Volam ukoncovaciu rutinu
            }
            else
            {
                IFileExplorer_ProgressForm_ResultInfo F = new IFileExplorer_ProgressForm_ResultInfo(360, pResultMessage);
                F.ParentPanel = this; F.FinishProcedure = pRoutine;
                F.SetParent(this); F.BringToFront(); // Zobrazim info okno
                FCurrentWorkProgressForm = F; F.ActivatePanel();
                IApp.AppForm.SetTabIcon(this, 1); // Nastavim ikonu informacie
            }
            IApp.App.EnabledEscMonitor = true;
        }
        /// <summary>Zobrazenie </summary>
        /// <param name="pCaption">text nad volbami</param>
        /// <param name="pNames">nazvy</param>
        /// <param name="pNotes">popisy</param>
        /// <param name="pDefaultChoice">prednastavena volba</param>
        /// <param name="pReserved">rezervovany parameter</param>
        /// <returns>-1 - stlaceny cancel, 0 az N vybrana volna</returns>
        public int ShowEditor_ChooseFromList(string pCaption, string pNames, string pNotes, int pDefaultChoice, int pReserved = -1)
        {
            if (InvokeRequired) // Potrebne invoke?
            {
                Invoke(new Delegate_ShowEditor_ChooseFromList(ShowEditor_ChooseFromList), new object[] {pCaption, pNames, pNotes, pDefaultChoice, pReserved}); // Vytvorim formular
                while (FCurrentChoiceForm.CurrentState.IntValue == -1) System.Threading.Thread.Sleep(10); // Cakam na vyber
                Invoke(new Delegate_ShowEditor_ChooseFromList(ShowEditor_ChooseFromList), new object[] { pCaption, pNames, pNotes, pDefaultChoice, -2 }); // Zrusim formular
                return FCurrentChoiceFormResultValue; // Vratim volbu
            }

            switch (pReserved)
            {
                case -1: // Vytvorenie formulara?
                    {
                        FCurrentChoiceForm = new IFileExplorer_ProgressForm_ChooseFromList(this, 400, pCaption, pNames, pNotes, pDefaultChoice);
                        FCurrentChoiceForm.SetParent(this); FCurrentChoiceForm.BringToFront();
                        FCurrentChoiceForm.ActivatePanel();
                        FCurrentWorkProgressForm.Enabled = false;
                        IApp.AppForm.SetTabIcon(this, 2); // Nastavim ikonu otazky
                    } break;
                case -2: // Zrusenie formulara?
                    {
                        FCurrentChoiceFormResultValue = FCurrentChoiceForm.ResultChoice;
                        FCurrentChoiceForm.Dispose(); FCurrentChoiceForm = null;
                        FCurrentWorkProgressForm.Enabled = true; FCurrentWorkProgressForm.ActivatePanel();
                        IApp.AppForm.SetTabIcon(this, 0); // Nastavim ikonu spracovania
                    } break;
            }
            return 0;
        }
        /// <summary>Nahradenie progress okna</summary>
        /// <param name="pProgressForm">nove okno</param>
        public void ReplaceProgressForm(IFileExplorer_BaseProgressForm pProgressForm)
        {
            if (InvokeRequired)
            {
                Invoke(new Delegate_ReplaceProgressForm(ReplaceProgressForm), new object[] { pProgressForm });
                return;
            }

            if (FCurrentWorkProgressForm != null) // Zrusim aktualne okno
            {
                Controls.Remove(FCurrentWorkProgressForm);
                FCurrentWorkProgressForm.Dispose();
                FCurrentWorkProgressForm = null;
            }

            FCurrentWorkProgressForm = pProgressForm; // Ulozim nove okno
            pProgressForm.SetParent(this); pProgressForm.BringToFront(); // Zobrazim progress okno
            pProgressForm.ActivatePanel();
        }
        /// <summary>Zobrazenie </summary>
        /// <param name="pCaption">text nad volbami</param>
        /// <param name="pNames">nazvy</param>
        /// <param name="pNotes">popisy</param>
        /// <param name="pDefaultChoice">prednastavena volba</param>
        /// <param name="pReserved">rezervovany parameter</param>
        /// <returns>-1 - stlaceny cancel, 0 az N vybrana volna</returns>
        public string ShowEditor_EditString(string pCaption, string Value, bool pCanBeEmpty, int pMaxLength, string pAutoCompleteResourceName, string pAutoCompleteData, bool pPasswordMode, int pReserved = -1)
        {
            if (InvokeRequired) // Potrebne invoke?
            {
                Invoke(new Delegate_ShowEditor_EditString(ShowEditor_EditString), new object[] { pCaption, Value, pCanBeEmpty, pMaxLength, pAutoCompleteResourceName, pAutoCompleteData, pPasswordMode, pReserved }); // Vytvorim formular
                while (FCurrentEditStringForm.CurrentState.IntValue == -1) System.Threading.Thread.Sleep(10); // Cakam na vyber
                Invoke(new Delegate_ShowEditor_EditString(ShowEditor_EditString), new object[] { pCaption, Value, pCanBeEmpty, pMaxLength, pAutoCompleteResourceName, pAutoCompleteData, pPasswordMode, -2 }); // Zrusim formular
                return FCurrentEditStringFormResultValue; // Vratim volbu
            }

            switch (pReserved)
            {
                case -1: // Vytvorenie formulara?
                    {
                        FCurrentEditStringForm = new IFileExplorer_ProgressForm_EditString(this, 400, pCaption, Value, pCanBeEmpty, pMaxLength, pAutoCompleteResourceName, pAutoCompleteData, pPasswordMode);
                        FCurrentEditStringForm.SetParent(this); FCurrentEditStringForm.BringToFront();
                        FCurrentEditStringForm.ActivatePanel();
                        FCurrentWorkProgressForm.Enabled = false;
                        IApp.AppForm.SetTabIcon(this, 2); // Nastavim ikonu otazky
                    } break;
                case -2: // Zrusenie formulara?
                    {
                        FCurrentEditStringFormResultValue = FCurrentEditStringForm.Value;
                        FCurrentEditStringForm.Dispose(); FCurrentEditStringForm = null;
                        FCurrentWorkProgressForm.Enabled = true; FCurrentWorkProgressForm.ActivatePanel();
                        IApp.AppForm.SetTabIcon(this, 0); // Nastavim ikonu spracovania
                    } break;
            }
            return null;
        }
    }
}
